{include file="common:theader" /}
{include file="common:tside" /}
    <div id="page-wrapper">
      <!-- 舆情日报 -->
      <!--*************************** content部分开始 ******************-->
      <div class="container-fluid" id="m_main">
        <div class="row m-t-20">
          <div class="col-sm-12">
            <div class="white-box">
              <h2 class="box-title m-b-20">课件课程管理</h2>
              <div class="row">
                <div class="di fl p-l-15 m-r-30">
                  <a href="/dboard/acourseware/add_course" class="btn btn-outline btn-info p-l-34 p-r-34">添加课件主题</a>
                </div>
              </div>
            </div>
            <div class="white-box">
              <div class="table-responsive">
                <table id="myTable" class="table table-striped color-table">
                  <thead>
                    <tr>
                      <th>序号</th>
                      <th>课件主题</th>
                      <th>上级</th>
                      <!-- <th>类型</th> -->
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr v-for="(item,index) in dataList">
                      <td>{{item.sort}}</td>
                      <td>{{item.name}}</td>
                      <td>{{item.pname}}</td>
                      <!-- <td>{{item.type}}</td> -->
                      <td>
                        <div>
                          <a :href="'/dboard/acourseware/edit_course?id=' + item.id" class="info m-r-15">编辑</a>
                          <a class="info edit" v-if="item.status==0" @click="statusChange(item.id,item.status)">启用</a>
                          <a class="danger edit" v-if="item.status==1" @click="statusChange(item.id,item.status)">删除</a>
                        </div>
                      </td>
                    </tr>
                  </tbody>
                </table>
                <pagination :tr-all="trAll" :page-cur="pageCur" :page-all="pageAll" :page-size="pageSize" @page-to="pageTo" ref="c1"></pagination>
              </div>
            </div>
          </div>
        </div>

        <!-- /.row -->
      </div>
      <!--*************************** content部分结束 ******************-->

      <!-- <footer class="footer text-center"> 2017 &copy; Ample Admin brought to you by themedesigner.in </footer> -->
    </div>
  {include file="common:js" /}
  {include file="common:footer" /}
  <script type="text/javascript" src="/web/js/search_list.js"></script>
  {include file="component:pagination" /}
  {include file="component:confirm" /}

  <script type="text/javascript">
    var vm = new Vue({
      el: '#m_main',
      data() {
        return {
          searchUrl: "/dboard/acourseware/course_lists", //搜索接口
          draw: '', //校验字段
          dataList: [], //搜索列表数据
          trAll: 0, //数据总数
          pageAll: 0, //页码总数
          pageCur: 1, //当前页
          pageSize: 10, //每页数量
        }
      },
      mounted() {
        this.pageTo(1);
      },
      methods: {
        // 搜索当前页并渲染列表
        pageTo(page) {
          var that = this;
          var params = {};
          searchList(that, page, params, (res) => {
            that.dataList = res.data.Data.courseware;
          }, (fail) => {}, (error) => {})
        },
        // 删除当前记录
        statusChange(...e){
          var that = this;
          var param = {id: e[0]};
          if(e[1] == 1) {
            param.status = 0
          } else {
            param.status = 1
          }
          axios.post('/dboard/acourseware/updateCoursewareCourse', param,{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              // 更新当前页内容
                    that.pageTo(that.pageCur);
            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        }
      }
    })
  </script>
